import 'mod.n'

fn main() {
    // 1. 一般泛型函数
    i32 a = 100
    i32 b = -1002
    var c = mod.sum(a, b)
    println(c)

    // 2. 一般泛型函数类型异常(需要注释掉 as 部分)
    i32 a2 = 333
    i16 b2 = 666
    var c2 = mod.sum(a2 as i16, b2)
    println(c2)

    // 3. 一般泛型函数指定类型
    i8 a3 = 12
    i32 b3 = 28
    var c3 = mod.sum<f32>(a3 as f32, b3 as f32)
    println(c3)

    // 4. 歧义场景测试
    var a4 = 12
    var b4 = 14

    // var c4 = a4 < b4 | a4 > (b4) // 编译时错误: 20230616_00_gen_fn/main.n:6:26: binary operator '|' only integer operand

    var d4 = a4 < b4 && a4 >(b4)
    println(d4) // false

    var e4 = [a4 < b4, a4 > b4]
    println(e4[0], e4[1]) // true false

    // var f4 = [a4 < b4, a4 > (b4)] // 编译时错误: 20230616_00_gen_fn/main.n:15:17: ident=b4 not type

    var g4 = [(a4 < b4), a4 > (b4)]
    println(g4[0], g4[1]) // true false

    // 5. 类型参数与泛型函数结合
    i16 a5 = 12
    var b5 = mod.box<i16, i32>{
        width: a5,
        length: 12,
    }

    var c5 = mod.area(b5)
    println(c5)

    // 6. 类型扩展
    var a6 = b5.perimeter()
    println(a6)


    // 7. 嵌套类型测试 1
    var a7 = mod.box<mod.custom_t<i32>, i16>{
        width: 66,
        length: 77,
    }

    println(a7.width, a7.length, mod.area(a7))
    println(a7.perimeter())


    // 8. 嵌套类型测试 2
    i16 b8  = 12
    var a8 = mod.person_t<string>{
        name: "hello",
        age: b8 as mod.custom_t<i8>,
    }
    println(a8.name, a8.age)
}
